<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="p" %>
<s:include value="/js/validators/user.jsp"></s:include>
<div class="f_l margin1" style="width:100%">

  <div style="height:24px;color:red" align="center" id="errorInfo">${failInfo }</div>
  <div style="height:24px;color:red;font-weight:bold" align="left">新建用户</div>
  <s:form id="submitForm" action="/user/user!save" method="post" theme="simple">
  <table>
  	<tbody>
  		<tr>
  			<td width="10%"><s:text name="用户名"/>：&nbsp;&nbsp;</td>
  			<td width="40%"><input maxlength="25" type="text" name="user.userName" value="${user.userName }" /></td>
  			<td width="10%"><s:text name="电子邮件"/>：</td>
  			<td width="40%"><input type="text" maxlength="25" name="user.email" value="${user.email }" /></td>
  		</tr>
  		<tr>
  			<td><s:text name="设置密码"/>：</td>
  			<td><input maxlength="14" type="password" name="user.password" /></td>
  			<td><s:text name="确认密码"/>：</td>
  			<td><input maxlength="14" type="password" name="user.repassword" /></td>
  		</tr>
  		<tr>
  			<td><s:text name="手     机" />：</td>
  			<td><input maxlength="13" type="text" name="user.mobile" value="${user.mobile }" /></td>
  			<td><s:text name="传    真" />：</td>
  			<td><input maxlength="25" type="text" name="user.fax" value="${user.fax }" /></td>
  		</tr>
  		<tr>
  			<td><s:text name="公    司"/>：</td>
  			<td>
  			  ${company.name}
  			  <input type="hidden" id="user.companyName" name="user.companyName" value="${company.name}">
              <input type="hidden" id="user.companyId" name="user.companyId" value="${company.id}">
            </td>
  			<td><s:text name="职位"/>：</td>
  			<td>
  				<select onchange="javascript:commonSelect(this,'user.positionName');" name="user.positionId" id="positions">
              		<s:iterator value="allPositions" status="status">
		                <option value="${id}">${name}</option>
		            </s:iterator>
          		</select>
            </td>
  		</tr>
  		<tr>
  			<td><s:text name="类     型"/>：</td>
  			<td>
  			    <select onchange="javascript:commonSelect(this,'user.userTypeName');" name="user.userTypeId" >
		                <option value="">-- 请选择 --</option>
			            <s:iterator value="allUsertypes" status="status">
			                <option value="${id}">${name}</option>
			            </s:iterator>
		        </select>
            </td>
  		</tr>
  		<tr>
  			<td colspan="4">
  			    <s:text name="国家"/>：<input maxlength="25" type="text" name="user.country" value="${user.country }" />
          		<s:text name="省"/>：<input maxlength="25" type="text" name="user.province" value="${user.province }" />
          		<s:text name="市"/>：<input maxlength="25" type="text" name="user.city" value="${user.city }" />
  			</td>
  		</tr>
  		<tr>
  			<td colspan="4"><s:text name="地址"/>：
  				<input maxlength="50" type="text" name="user.address" value="${user.address }" style="width: 450px;">
 			</td>
  		</tr>
  		<tr>
  			<td colspan="2" align="right">
  			  <input type="submit" value="确认" onclick="return doValidate(event);" />
 			</td>
  			<td colspan="2" align="left">
  				<input type="button" value="取消" onclick="window.location.href='user!list'"/>
  			</td>
  		</tr>
  	</tbody>
  </table>
  <input type="hidden" id="user.userTypeName" name="user.userTypeName" />
  <input type="hidden" id="user.positionName" name="user.positionName" />
  </s:form>
</div>
  
<script>
function getPositions(){
    var companyId = document.getElementById("user.companyId").value;
    $.ajax({
  	  type: "POST",
  	  url: "<s:url action='position!getPositionsByCompanyId' namespace='/position' />",
  	  data: "companyId=" + companyId,
  	  complete:function(response){
        var data = response.responseText;
  	  if(null != data && "" != data){
		       var positions = data.split(";");
		       var html = "";
		       for(var i = 0; i < positions.length; i++){
		           var p = positions[i].split(",");
		           html += "<option value='" + p[0]+ "'>" + p[1] + "</option>";
		       }
		       $("#positions").html(html);
	        }else{
	           $("#positions").html("<option value=''>无</option>");
	        }
        }
    }); 
}

</script>
